package com.jx.controller.admin.content;

import com.jx.common.result.AjaxResult;
import com.jx.pojo.entity.content.Category;
import com.jx.pojo.entity.system.Menu;
import com.jx.pojo.po.content.CategoryPO;
import com.jx.pojo.po.content.CategoryTree;
import com.jx.pojo.po.system.MenuPO;
import com.jx.pojo.po.system.MenuTree;
import com.jx.pojo.vo.content.CategoryVO;
import com.jx.pojo.vo.system.MenuVO;
import com.jx.service.content.CategoryService;
import com.jx.service.system.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 文章类别 相关接口
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * 获取类别列表
     */
    @GetMapping("/list")
    public AjaxResult list(CategoryVO query) {
        List<CategoryPO> list = categoryService.listCategory(query);
        return AjaxResult.success(list);
    }

    /**
     * 保存菜单
     */
    @PostMapping("/save")
    public AjaxResult saveMenu(@RequestBody Category category) {
        categoryService.saveCategory(category);
        return AjaxResult.success("菜单保存成功");
    }

    /**
     * 根据id删除菜单
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Integer id) {
        categoryService.removeById(id);
        return AjaxResult.success("菜单删除成功");
    }

    /**
     * 根据id获取菜单详情
     */
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam Integer id) {
        Category category = categoryService.getById(id);
        return AjaxResult.success(category);
    }

    /**
     * 获取目录列表
     */
    @GetMapping("/getDirList")
    public AjaxResult getDirList() {
        List<Object> result = categoryService.getDirList();
        return AjaxResult.success(result);
    }

    /**
     * 获取树
     */
    @GetMapping("/getTree")
    public AjaxResult getTree() {
        List<CategoryTree> result =  categoryService.getTree();
        return AjaxResult.success(result);
    }

    /**
     * 获取分组数据
     */
    @GetMapping("/getOptions")
    public AjaxResult getOptions() {
        List<Map<String,Object>> result =  categoryService.getOptions();
        return AjaxResult.success(result);
    }


}
